module FilterEngine

  def columns_for(query)
    ActiveRecord::Schema.columns(query.table_name)
  end

  def create_criteria(query, column_name)
    columns_ = columns_for(query)
    columns = { }
    columns_.each do |col|
      columns[col.name] = col
    end
    column = columns[column_name]
    if column.nil?
      column = columns[query.get_foreign(column_name)]
    end
    return Criteria.new(query, column)
  end

  def operations_for(criteria)
    if criteria.type==:integer
      return ['=', '!=']
    end
    if criteria.type==:string
      return ['like', '!=']
    end
    if criteria.type==:text
      return ['like', '!=']
    end
  end

end
